import subprocess
import os
import sys

def convert_qrc_to_py(input_qrc, output_py):
    # 获取当前 Python 环境的 Scripts 目录
    scripts_dir = os.path.join(os.path.dirname(sys.executable))
    pyside6_rcc = os.path.join(scripts_dir, 'pyside6-rcc.exe')

    if not os.path.exists(pyside6_rcc):
        print(f"Error: {pyside6_rcc} not found")
        return

    try:
        # 使用 subprocess 直接调用 pyside6-rcc 工具
        subprocess.check_call([pyside6_rcc, '-o', output_py, input_qrc])
        print(f"Successfully converted {input_qrc} to {output_py}")
    except subprocess.CalledProcessError as e:
        print(f"Error converting {input_qrc} to {output_py}: {e}")

input_qrc = 'resources.qrc'
output_py = 'resources.py'

convert_qrc_to_py(input_qrc, output_py)
